<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get file handler for entry</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="rarentry.getpackedsize.html">« RarEntry::getPackedSize</a></li>
      <li style="float: right;"><a href="rarentry.getunpackedsize.html">RarEntry::getUnpackedSize »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.rarentry.html">RarEntry</a></li>
    <li>Get file handler for entry</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="rarentry.getstream" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">RarEntry::getStream</h1>
  <p class="verinfo">(PECL rar &gt;= 2.0.0)</p><p class="refpurpose"><span class="refname">RarEntry::getStream</span> &mdash; <span class="dc-title">Get file handler for entry</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-rarentry.getstream-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>RarEntry::getStream</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type">resource</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Returns a file handler that
   supports read operations. This handler provides on-the-fly decompression
   for this entry.
  </p>
  <p class="para">
    The handler is not invalidated by calling
    <span class="function"><a href="rararchive.close.html" class="function">rar_close()</a></span>.
  </p>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="para">The resulting stream has no integrity verification. In particular, file corruption and
   decryption with a wrong a key will not be detected. It is the programmer&#039;s responsability to use the entry&#039;s CRC
   to check for integrity, if he so wishes.</p>
  </div>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-rarentry.getstream-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">password</code></dt>

     <dd>

      <p class="para">
       The password used to encrypt this entry. If the entry is not encrypted, this value will not be used and can
       be omitted. If this parameter is omitted and the entry is encrypted, the password given to
       <span class="function"><a href="rararchive.open.html" class="function">rar_open()</a></span>, if any, will be used. If a wrong password is given, either explicitly
       or implicitly via <span class="function"><a href="rararchive.open.html" class="function">rar_open()</a></span>, this method&#039;s resulting stream will produce wrong
       output. If no password is given and one is required, this method will fail and return <strong><code>false</code></strong>.
       You can check whether an entry is encrypted with <span class="methodname"><a href="rarentry.isencrypted.html" class="methodname">RarEntry::isEncrypted()</a></span>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-rarentry.getstream-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The file handler  或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-rarentry.getstream-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL rar 3.0.0</td>
       <td>
        Support for RAR archives with repeated entry names is no longer defective.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-rarentry.getstream-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-821">
    <p><strong>示例 #1 <span class="methodname"><strong>RarEntry::getStream()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$rar_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'example.rar'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$rar_file&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;open&nbsp;Rar&nbsp;archive"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_entry_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$rar_file</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Dir/file.txt'</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;find&nbsp;such&nbsp;entry"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stream&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getStream</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">$stream&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;obtain&nbsp;stream."</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">rar_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$rar_file</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//stream&nbsp;is&nbsp;independent&nbsp;from&nbsp;file<br /><br /></span><span style="color: #007700">while&nbsp;(!</span><span style="color: #0000BB">feof</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$buff&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">8192</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$buff&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$buff</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;</span><span style="color: #FF8000">//fread&nbsp;error<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-rarentry.getstream-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="rarentry.extract.html" class="methodname" rel="rdfs-seeAlso">RarEntry::extract()</a> - Extract entry from the archive</span></li>
    <li class="member"><a href="wrappers.rar.html" class="link"><code class="literal">rar://</code> wrapper</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>